//
//  PYImageFileController.m
//  IHome
//
//   Created by zhujizheng on 2020/2/18.
//  Copyright © 2019年 com.zhujizheng. All rights reserved.
//

#import "PYImageFileController.h"

@interface PYImageFileController ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UIImage *image;
@end

@implementation PYImageFileController

- (BOOL)autoFitSizeForNaviTitle
{
    return YES;
}

+ (instancetype)controllerWithImage:(UIImage *)image
{
    PYImageFileController *controller = [PYImageFileController new];
    controller.image = image;
    return controller;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initImgView];
    self.imgView.image = self.image;
    CGFloat scale = [UIScreen mainScreen].scale;
    CGSize size = CGSizeMake(self.image.size.width / scale, self.image.size.height / scale);
    if (size.width > APP_WIDTH) {
        size.width = APP_WIDTH;
        size.height = APP_WIDTH * self.image.size.height / self.image.size.width;
        if (size.height > APP_HEIGHT) {
            size.height = APP_HEIGHT;
        }
    } else if (size.height > APP_HEIGHT) {
        size.height = APP_HEIGHT;
        size.width = APP_HEIGHT * self.image.size.width / self.image.size.height;
        if (size.width > APP_WIDTH) {
            size.width = APP_WIDTH;
        }
    }
    
    [self.imgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(size);
    }];
}

#pragma mark - imgView
- (UIImageView *)imgView
{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imgView;
}

- (void)initImgView
{
    [self.view addSubview:self.imgView];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeZero);
    }];
}

@end
